import {Feature} from 'ol'
import {Point} from 'ol/geom'
import {Style,Fill,Circle} from 'ol/style'
//定义屏幕的分辨率
const DESIGNWIDTH = 1920;
const DESIGNHEIGHT = 1080;

const styleUtil = {
    px2vw:(_px)=> _px / DESIGNWIDTH * 100 + 'vw',
    px2vh:(_px)=>_px / DESIGNHEIGHT * 100 + 'vh',
    px2font:(_px)=>_px / DESIGNWIDTH * 100 + 'vw',
    //根据当前设备的像素比返回对应的背景图片url
    getBackImageUrlByPixelRatio:(name)=>{
        if(window.devicePixelRatio >= 2){
            name = name + "@2x.png";
        }else{
            name = name + "@1x.png";
        }
        return name;
    }
}
export default styleUtil;

//点击列表图非跳转并添加高亮
export const createHighLayer = (highLayer,row)=>{
    const lat = parseFloat(row.longitude);
        const lng = parseFloat(row.latitude);
        const feature = new Feature({
          geometry: new Point([lat, lng]),
        });
       let radius;
       if(parseFloat(row.arearain) >= 20 ){
        radius = parseFloat(row.arearain) ;
       }else if(parseFloat(row.arearain) <=10  ){
        radius = parseFloat(row.arearain) * 2;
       }else if(parseFloat(row.arearain) >=50){
        radius = 50;
       }else{
        radius = parseFloat(row.arearain);
       }
        //添加高亮点图层
        if (row.status_difference > 0) {
          feature.setStyle(
            new Style({
              image: new Circle({
                radius: radius,
                fill: new Fill({
                  color: "red",
                }),
              }),
            })
          );
        }
        else {
          feature.setStyle(
            new Style({
              image: new Circle({
                radius: radius,
                fill: new Fill({
                  color: "green",
                }),
              }),
            })
          );
        }
      highLayer.getSource().addFeature(feature);
      return highLayer;
}